{extend name="public/base"/} {block name="body"}
<link rel="stylesheet" type="text/css" href="__PUBLIC__/xsd/css/checkout.css" />
<style>
.addresscard-del {
    -ms-flex-preferred-size: 1.306667rem;
    flex-basis: 1.306667rem;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: end;
    -ms-flex-pack: end;
    justify-content: flex-end;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
}
</style>
<header class="mui-bar mui-bar-nav" style="z-index:7">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 class="mui-title">选择地址</h1>
</header>
<div class="mui-content ">
    {volist name="list" id="vo"}
    <div class="addresscard">
        {eq name="$vo['defaults']" value='1'}
        <div class="addresscard-select"><img src="__PUBLIC__/xsd/img/gg.png"></div>{/eq}
        <div class="addresscard-body" data-addressid="{$vo.id}">
            <p class="addresscard-title"> <span class="username">{$vo.name}</span> <span class="gender">{eq name="$vo['sex']" value='1'}先生{else /}女士{/eq}</span> <span class="tpl">{$vo.tel}</span> </p>
            <p class="addresscard-address"> <span class="address-tag" style="display: none;"></span> <span class="address-text">{$vo.first_area|parse_config_value='delivery_area'} {$vo.second_area|get_table_field="id","second_area","DeliveryArea"} {$vo.address}</span> </p>
        </div>
        <a class="addresscard-edit" href="{:url('index/address/add', array('id'=>$vo['id']))}"> <span class="mui-icon mui-icon-compose"></span></a>
        <a class="addresscard-del" href="javascript:;" data-id="{$vo['id']}"> <span class="mui-icon mui-icon-trash"></span> </a>
    </div>
    {/volist}
    <div class="addressview-bottom">
        <div class="bottom-text" id="add"><span class="mui-icon mui-icon-plus-filled"></span> 新增收货地址</div>
    </div>
</div>
{/block}
{block name="script"}
  <script type="text/javascript">
    $(function(){
      $('#add').on('click',function(){
        window.location.href = "{:url('index/address/add')}"
      })

      $('.addresscard-body').click(function(){
        var $this = $(this),id = $this.attr('data-addressid')
        $.post("{:url('index/address/setDefaults')}", {
            "id": id
        }, function(data) {
            mui.toast('设为默认地址成功！')
            setTimeout(function() {
                mui.back()
            }, 2000);

        }, "json");
      })

      $('.addresscard-del').on('click', function(){
        var id = $(this).attr('data-id')
        var btnArray = ['否', '是'];
        mui.confirm('您确定要删除地址吗？', '删除地址', btnArray, function(e) {
          if (e.index == 1) {
              $.post("{:url('index/address/del')}", {
                  "id": id
              }, function(data) {
                  mui.toast('删除成功！')
                  setTimeout(function() {
                    location.reload()
                  }, 2000);
              }, "json");

          } else {
            return ;
          }
        })
      })
    })
  </script>
{/block}
